<template>
  <ImageList :data="imageList">
    <div class="page noBlueBg blackBg">
      <el-pagination
        @current-change="changePage"
        :current-page="page"
        :page-size="limit"
        layout="total,prev, pager, next, jumper"
        :total="totals">
      </el-pagination>
      <div class="groupBy ml20">
        <el-select v-model="groupType" placeholder="请选择分组类型" size="mini" clearable style="width: 120px;display: inline-block">
          <el-option
            v-for="(value,key) in groups"
            :key="key"
            :label="value"
            :value="key.toString()">
          </el-option>
        </el-select>
        <el-input v-model="groupValue" placeholder="请输入分组名称" style="width: 120px;" size="mini" class="mh5" clearable></el-input>
        <el-button size="mini" type="primary" @click="loadData">查询分组</el-button>
      </div>
    </div>
  </ImageList>
</template>

<script>

  import ImageList from "comp/common/ImageList";

  export default {
    name: "ImageMode",
    components: {
      ImageList
    },
    data() {
      return {
        groups: this.$kkui.cache.get('dict')['cameraGroup'],
        dict: this.$kkui.cache.get('dict'),
        imageList: [],

        liveEvtIndex: null,

        limit: 12,
        page: 1,
        pages: 1,
        totals: 0,
        groupType:'',
        groupValue:'',
      }
    },
    mounted() {
      this.loadData();
    },
    methods: {
      loadData() {
        this.$server('monitor.list', {
          limit: this.limit,
          page: this.page,
          state: 0,
          groupType:this.groupType,
          groupValue:this.groupValue
        }).then(data => {
          this.imageList = data['records'].map(item => {
            const camera = item['bscCamera'];
            if(!camera) return  false;
            const id = item.id,
              code = item['eventTypeTwoCode'],
              color = WebCfg.eventColor[code],
              name = this.dict['event'][code],
              gis = [camera['longitude'], camera['latitude']];
            return {

              source:item.source,
              id,
              type: 'event',
              videoPath: item.videoPath,
              url: item.imgPath,
              imagePath: item.imgPath,
              event: item.code,
              state: this.dict['status'][item.state],
              items: [
                {
                  key: 'type',
                  label: '类型',
                  value: name,
                  color
                },
                {
                  key: 'state',
                  label: '状态',
                  value: this.dict['status'][item.state],
                  color
                },
                {
                  key: 'road',
                  label: '路段',
                  value: camera['road'],
                  color
                },
                {
                  key: 'pos',
                  label: '位置',
                  value: camera['name'],
                  color
                }
              ]
            }
          });
          this.totals = data['total'];
          this.$kkui.loading_deepBlue.hide();
        })
      },

      //切换分页
      changePage(page) {
        this.page = page;
        this.loadData();
      },

    }

  }
</script>

<style scoped>

</style>
